﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class CreateUVConvetObject
{
   [MenuItem("Assets/Create/UVConvertObject")]
   public static void CreateUVConverter()
    {
        var instance = ScriptableObject.CreateInstance<CustomUvMapper>();
        var path = AssetDatabase.GenerateUniqueAssetPath(GetActiveFolderPath() + "/" + "converter.asset");
        AssetDatabase.CreateAsset(instance, 
           path);
        AssetDatabase.SaveAssets();


    }

    static string GetActiveFolderPath()
    {
#if UNITY_2018 || UNITY_2019 || UNITY_2020_1
        //源码里这个方法是internal的，只能反射调用
        var mi = typeof(ProjectWindowUtil).GetMethod("GetActiveFolderPath",
            System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
#endif
        return mi.Invoke(null, null) as string;
    }

}
